package dLogistic.test;

import dLogistic.application.service.PaczkaService;
import dLogistic.domain.model.Klient.KlientAggr;
import dLogistic.domain.model.Klient.KlientFactory;
import dLogistic.domain.model.Klient.KlientRepository;
import dLogistic.domain.model.Kurier.KurierAggr;
import dLogistic.domain.model.Kurier.KurierFactory;
import dLogistic.domain.model.Kurier.KurierRepository;
import dLogistic.domain.model.Magazyn.MagazynAggr;
import dLogistic.domain.model.Magazyn.MagazynFactory;
import dLogistic.domain.model.Paczka.PaczkaAggr;
import dLogistic.domain.model.Paczka.PaczkaFactory;
import dLogistic.domain.model.sharedValueObjects.Adres;
import dLogistic.domain.service.GeolokalizacjaService;
import dLogistic.domain.service.KurierService;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.ArrayList;
import java.util.UUID;

/**
 * Created by Przemek on 2014-11-02.
 */
public class OknoAplikacji {
    private static SessionFactory factory;
    static final int RESULT_CANCEL=0;
    static final int RESULT_OK=1;
    int result = RESULT_CANCEL;

    public OknoAplikacji() {
        try{
            factory = new Configuration().configure("/resources/hibernate.cfg.xml").buildSessionFactory();
        }catch (Throwable ex) {
            System.err.println("Failed to create sessionFactory object." + ex);
            throw new ExceptionInInitializerError(ex);
        }

        JFrame frame = new JFrame();
        frame.setLocation(100,100);
        frame.setTitle("dLogistic");
        frame.setSize(500, 500);

        JTabbedPane jtp = new JTabbedPane( );
        jtp.addTab("<html><font color=red>Paczka</font>", new z1( ));
        jtp.addTab("<html><font color=green>Klient</font>", new z2( ));
        jtp.addTab("<html><font color=blue>Kurier</font>", new z3( ));
        jtp.addTab("<html><font color=purple>Magazyn</font>", new z4( ));

        frame.add(jtp);
        frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });

        frame.setVisible(true);

    }

    public void OknoKlientLogowanie(){
        final JFrame frame = new JFrame();
        frame.setLocation(100,100);
        frame.setTitle("dLogistic - klient");
        frame.setSize(800, 400);
        final JPanel panel=new JPanel();
        panel.setLayout(null);
        frame.add(panel);

        JLabel label1 = new JLabel();
        JLabel label2 = new JLabel();
        JLabel label3 = new JLabel();
        JLabel label4 = new JLabel();
        JLabel label5 = new JLabel();
        JLabel label6 = new JLabel();
        JLabel label7 = new JLabel();
        JLabel label8 = new JLabel();
        JLabel label9 = new JLabel();
        JLabel label10 = new JLabel();

        label1.setText("imie");
        label2.setText("nazwisko");
        label3.setText("telefon");
        label4.setText("email");
        label5.setText("ulica");
        label6.setText("numer domu");
        label7.setText("numer lokalu");
        label8.setText("kod");
        label9.setText("miasto");
        label10.setText("uuid");

        label1.setBounds(10, 10, 80, 20);
        label2.setBounds(10, 40, 80, 20);
        label3.setBounds(10, 70, 80, 20);
        label4.setBounds(10, 100, 80, 20);
        label5.setBounds(10, 130, 80, 20);
        label6.setBounds(10, 160, 80, 20);
        label7.setBounds(10, 190, 80, 20);
        label8.setBounds(10, 220, 80, 20);
        label9.setBounds(10, 250, 80, 20);
        label10.setBounds(10, 300, 80, 20);

        panel.add(label1);
        panel.add(label2);
        panel.add(label3);
        panel.add(label4);
        panel.add(label5);
        panel.add(label6);
        panel.add(label7);
        panel.add(label8);
        panel.add(label9);
        panel.add(label10);

        final JTextField nadawca_imie = new JTextField();
        final JTextField nadawca_nazwisko = new JTextField();
        final JTextField nadawca_telefon = new JTextField();
        final JTextField nadawca_email = new JTextField();
        final JTextField nadawca_ulica = new JTextField();
        final JTextField nadawca_numer_domu = new JTextField();
        final JTextField nadawca_numer_lokalu  = new JTextField();
        final JTextField nadawca_kod_pocztowy = new JTextField();
        final JTextField nadawca_miasto = new JTextField();
        final JTextField nadawca_uuid = new JTextField();

        nadawca_imie.setBounds(100, 10, 250, 20);
        nadawca_nazwisko.setBounds(100, 40, 250, 20);
        nadawca_telefon.setBounds(100, 70, 250, 20);
        nadawca_email.setBounds(100, 100, 250, 20);
        nadawca_ulica.setBounds(100, 130, 250, 20);
        nadawca_numer_domu.setBounds(100, 160, 250, 20);
        nadawca_numer_lokalu.setBounds(100, 190, 250, 20);
        nadawca_kod_pocztowy.setBounds(100, 220, 250, 20);
        nadawca_miasto.setBounds(100, 250, 250, 20);
        nadawca_uuid.setBounds(100, 300, 250, 20);

        panel.add(nadawca_imie);
        panel.add(nadawca_nazwisko);
        panel.add(nadawca_telefon);
        panel.add(nadawca_email);
        panel.add(nadawca_ulica);
        panel.add(nadawca_numer_domu);
        panel.add(nadawca_numer_lokalu);
        panel.add(nadawca_kod_pocztowy);
        panel.add(nadawca_miasto);
        panel.add(nadawca_uuid);

        /*   */
        JLabel label11 = new JLabel();
        JLabel label12 = new JLabel();
        JLabel label13 = new JLabel();
        JLabel label14 = new JLabel();
        JLabel label15 = new JLabel();
        JLabel label16 = new JLabel();
        JLabel label17 = new JLabel();
        JLabel label18 = new JLabel();
        JLabel label19 = new JLabel();
        JLabel label20 = new JLabel();

        label11.setText("imie");
        label12.setText("nazwisko");
        label13.setText("telefon");
        label14.setText("email");
        label15.setText("ulica");
        label16.setText("numer domu");
        label17.setText("numer lokalu");
        label18.setText("kod");
        label19.setText("miasto");
        label20.setText("uuid");

        label11.setBounds(410, 10, 80, 20);
        label12.setBounds(410, 40, 80, 20);
        label13.setBounds(410, 70, 80, 20);
        label14.setBounds(410, 100, 80, 20);
        label15.setBounds(410, 130, 80, 20);
        label16.setBounds(410, 160, 80, 20);
        label17.setBounds(410, 190, 80, 20);
        label18.setBounds(410, 220, 80, 20);
        label19.setBounds(410, 250, 80, 20);
        label20.setBounds(410, 300, 80, 20);

        panel.add(label11);
        panel.add(label12);
        panel.add(label13);
        panel.add(label14);
        panel.add(label15);
        panel.add(label16);
        panel.add(label17);
        panel.add(label18);
        panel.add(label19);
        panel.add(label20);

        final JTextField adresat_imie = new JTextField();
        final JTextField adresat_nazwisko = new JTextField();
        final JTextField adresat_telefon = new JTextField();
        final JTextField adresat_email = new JTextField();
        final JTextField adresat_ulica = new JTextField();
        final JTextField adresat_numer_domu = new JTextField();
        final JTextField adresat_numer_lokalu  = new JTextField();
        final JTextField adresat_kod_pocztowy = new JTextField();
        final JTextField adresat_miasto = new JTextField();
        final JTextField adresat_uuid = new JTextField();

        adresat_imie.setBounds(500, 10, 250, 20);
        adresat_nazwisko.setBounds(500, 40, 250, 20);
        adresat_telefon.setBounds(500, 70, 250, 20);
        adresat_email.setBounds(500, 100, 250, 20);
        adresat_ulica.setBounds(500, 130, 250, 20);
        adresat_numer_domu.setBounds(500, 160, 250, 20);
        adresat_numer_lokalu.setBounds(500, 190, 250, 20);
        adresat_kod_pocztowy.setBounds(500, 220, 250, 20);
        adresat_miasto.setBounds(500, 250, 250, 20);
        adresat_uuid.setBounds(500, 300, 250, 20);

        panel.add(adresat_imie);
        panel.add(adresat_nazwisko);
        panel.add(adresat_telefon);
        panel.add(adresat_email);
        panel.add(adresat_ulica);
        panel.add(adresat_numer_domu);
        panel.add(adresat_numer_lokalu);
        panel.add(adresat_kod_pocztowy);
        panel.add(adresat_miasto);
        panel.add(adresat_uuid);
        /*  */

        final JButton btn1 = new JButton("Zapisz");
        btn1.setBounds(300, 330, 100, 20);
        panel.add(btn1);

        final JButton btn2 = new JButton("Anuluj");
        btn2.setBounds(450, 330, 100, 20);
        //btn2.updateUI();
        panel.add(btn2);

        frame.setVisible(true);

        btn1.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                KlientRepository klientRepository = new KlientRepository();
                KlientFactory klientFactory = new KlientFactory();
                KlientAggr nadawca = null;
                KlientAggr adresat = null;
                if (nadawca_uuid.getText() != ""){
                    nadawca = klientRepository.znajdz(nadawca_uuid.getText());
                }
                if (nadawca == null){
                    UUID n_uuid = UUID.randomUUID();
                    nadawca = klientFactory.dodajKlienta(nadawca_imie.getText(), nadawca_nazwisko.getText(), nadawca_telefon.getText(), nadawca_email.getText());
                    Adres adresNadawca = new Adres(nadawca_ulica.getText(), nadawca_numer_domu.getText(), nadawca_numer_lokalu.getText(), nadawca_miasto.getText(), nadawca_kod_pocztowy.getText(), n_uuid.toString(), nadawca.uuid(), 0);
                }
                if (adresat_uuid.getText() != ""){
                    adresat = klientRepository.znajdz(adresat_uuid.getText());
                }
                if (adresat == null){
                    UUID a_uuid = UUID.randomUUID();
                    adresat = klientFactory.dodajKlienta(adresat_imie.getText(), adresat_nazwisko.getText(), adresat_telefon.getText(), adresat_email.getText());
                    Adres adresAdresat = new Adres(adresat_ulica.getText(), adresat_numer_domu.getText(), adresat_numer_lokalu.getText(), adresat_miasto.getText(), adresat_kod_pocztowy.getText(), a_uuid.toString(), adresat.uuid(), 0);
                }

                PaczkaFactory paczkaFactory = new PaczkaFactory();
                PaczkaAggr paczkaAggr = paczkaFactory.rejestrujPaczke(nadawca.uuid(), adresat.uuid());

                OknoPaczkaPotiwerdzenie(paczkaAggr.uuid(), nadawca.uuid(), adresat.uuid());
                frame.dispose();

                //return kli.uuid().toString();
            }
        });
        btn2.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                frame.dispose();
            }
        });
    }

    public void OknoPaczkaPotiwerdzenie(String paczka_uuid, String nadawca_uuid, String adresat_uuid){

        final JFrame frame = new JFrame();
        frame.setLocation(100,100);
        frame.setTitle("dLogistic - Potwierdzenie nadania");
        frame.setSize(400, 250);
        final JPanel panel=new JPanel();
        panel.setLayout(null);
        frame.add(panel);

        JLabel label1 = new JLabel();

        JLabel label2 = new JLabel();
        JLabel label3 = new JLabel();
        JLabel label4 = new JLabel();
        JLabel label5 = new JLabel();
        JLabel label6 = new JLabel();
        JLabel label7 = new JLabel();

        label1.setText("Potwierdzenie nadania paczki");
        label2.setText("Paczka - UUID");
        label3.setText("Nadawca - UUID");
        label4.setText("Adresat - UUID");
        label5.setText(paczka_uuid);
        label6.setText(nadawca_uuid);
        label7.setText(adresat_uuid);

        label1.setBounds(10, 10, 200, 20);
        label2.setBounds(10, 60, 100, 20);
        label3.setBounds(10, 100, 100, 20);
        label4.setBounds(10, 140, 100, 20);
        label5.setBounds(150, 60, 250, 20);
        label6.setBounds(150, 100, 250, 20);
        label7.setBounds(150, 140, 250, 20);

        panel.add(label1);
        panel.add(label2);
        panel.add(label3);
        panel.add(label4);
        panel.add(label5);
        panel.add(label6);
        panel.add(label7);

        final JButton btn2 = new JButton("OK");
        btn2.setBounds(250, 180, 100, 20);
        panel.add(btn2);

        frame.setVisible(true);

        btn2.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                frame.dispose();
            }
        });
    }

    public void OknoSprawdzStatus(){
        final JFrame frame = new JFrame();
        frame.setLocation(100,100);
        frame.setTitle("dLogistic - sprawdź status");
        frame.setSize(400, 120);
        final JPanel panel=new JPanel();
        panel.setLayout(null);
        frame.add(panel);

        JLabel label1 = new JLabel();
        label1.setText("uuid");
        label1.setBounds(10, 10, 80, 20);
        panel.add(label1);

        final JTextField uuid_paczka = new JTextField();
        uuid_paczka.setBounds(100, 10, 250, 20);
        panel.add(uuid_paczka);

        final JButton btn1 = new JButton("Sprawdź");
        btn1.setBounds(100, 40, 100, 20);
        panel.add(btn1);

        final JButton btn2 = new JButton("Anuluj");
        btn2.setBounds(250, 40, 100, 20);
        panel.add(btn2);

        frame.setVisible(true);

        btn1.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                PaczkaService paczkaService = new PaczkaService();
                JOptionPane.showMessageDialog(null, paczkaService.StatusPaczki(uuid_paczka.getText()));

                frame.dispose();
            }
        });
        btn2.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                frame.dispose();
            }
        });

    }

    public void OknoZmianStatus(){
        final JFrame frame = new JFrame();
        frame.setLocation(100,100);
        frame.setTitle("dLogistic - sprawdź status");
        frame.setSize(400, 220);
        final JPanel panel=new JPanel();
        panel.setLayout(null);
        frame.add(panel);

        JLabel label1 = new JLabel();
        JLabel label2 = new JLabel();
        JLabel label3 = new JLabel();
        JLabel label4 = new JLabel();

        label1.setText("paczka");
        label2.setText("przekazujący");
        label3.setText("odbierający");
        label4.setText("przekazanie");

        label1.setBounds(10, 10, 80, 20);
        label2.setBounds(10, 40, 80, 20);
        label3.setBounds(10, 70, 80, 20);
        label4.setBounds(10, 100, 80, 20);

        panel.add(label1);
        panel.add(label2);
        panel.add(label3);
        panel.add(label4);

        final JTextField uuid_paczka = new JTextField();
        uuid_paczka.setBounds(100, 10, 250, 20);
        panel.add(uuid_paczka);

        final JTextField przekazujacy = new JTextField();
        przekazujacy.setBounds(100, 40, 250, 20);
        panel.add(przekazujacy);

        final JTextField odbierajacy = new JTextField();
        odbierajacy.setBounds(100, 70, 250, 20);
        panel.add(odbierajacy);

        final JTextField przekazanie = new JTextField();
        przekazanie.setBounds(100, 100, 250, 20);
        panel.add(przekazanie);

        final JButton btn1 = new JButton("Zatwierdź");
        btn1.setBounds(100, 140, 100, 20);
        panel.add(btn1);

        final JButton btn2 = new JButton("Anuluj");
        btn2.setBounds(250, 140, 100, 20);
        panel.add(btn2);

        frame.setVisible(true);

        btn1.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                PaczkaService paczkaService = new PaczkaService();
                if (paczkaService.przekazaniePaczki(uuid_paczka.getText(),przekazujacy.getText(),odbierajacy.getText(),Integer.parseInt(przekazanie.getText()))){
                    JOptionPane.showMessageDialog(null,"Uaktualniono pomyślnie");
                }
                else{
                    JOptionPane.showMessageDialog(null,"Nastąpił błąd - nie wprowadzono zmian");
                }

//                JOptionPane.showMessageDialog(null, paczkaService.StatusPaczki(uuid_paczka.getText()));

                frame.dispose();
            }
        });
        btn2.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                frame.dispose();
            }
        });
    }

    public void OknoKurier(){
        final JFrame frame = new JFrame();
        frame.setLocation(100,100);
        frame.setTitle("dLogistic - kurier");
        frame.setSize(400, 120);
        final JPanel panel=new JPanel();
        panel.setLayout(null);
        frame.add(panel);

        JLabel label1 = new JLabel();
        label1.setText("nazwa");
        label1.setBounds(10, 10, 80, 20);
        panel.add(label1);

        final JTextField kurier_nazwa = new JTextField();
        kurier_nazwa.setBounds(100, 10, 250, 20);
        panel.add(kurier_nazwa);

        final JButton btn1 = new JButton("Zapisz");
        btn1.setBounds(100, 40, 100, 20);
        panel.add(btn1);

        final JButton btn2 = new JButton("Anuluj");
        btn2.setBounds(250, 40, 100, 20);
        panel.add(btn2);

        frame.setVisible(true);

        btn1.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                KurierFactory kurier = new KurierFactory();
                KurierAggr kur = kurier.dodajKuriera(kurier_nazwa.getText());
                frame.dispose();
            }
        });
        btn2.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                frame.dispose();
            }
        });
    }

    public void OknoKurierTrasa(){

        final JFrame frame = new JFrame();
        frame.setLocation(100,100);
        frame.setTitle("dLogistic - kurier trasa");
        frame.setSize(400, 260);
        final JPanel panel=new JPanel();
        panel.setLayout(null);
        frame.add(panel);

        JLabel label1 = new JLabel();
        JLabel label2 = new JLabel();
        JLabel label3 = new JLabel();
        JLabel label4 = new JLabel();
        JLabel label5 = new JLabel();
        JLabel label6 = new JLabel();

        label1.setText("kurier uuid");
        label2.setText("G - start");
        label3.setText("G - end");
        label4.setText("M - start");
        label5.setText("M - end");
        label6.setText("dzien");

        label1.setBounds(10, 10, 80, 20);
        label2.setBounds(10, 40, 80, 20);
        label3.setBounds(10, 70, 80, 20);
        label4.setBounds(10, 100, 80, 20);
        label5.setBounds(10, 130, 80, 20);
        label6.setBounds(10, 160, 80, 20);

        panel.add(label1);
        panel.add(label2);
        panel.add(label3);
        panel.add(label4);
        panel.add(label5);
        panel.add(label6);

        final JTextField kurier_uuid = new JTextField();
        kurier_uuid.setBounds(100, 10, 250, 20);
        panel.add(kurier_uuid);

        final JTextField data_start = new JTextField();
        data_start.setBounds(100, 40, 250, 20);
        panel.add(data_start);

        final JTextField data_end = new JTextField();
        data_end.setBounds(100, 70, 250, 20);
        panel.add(data_end);

        final JTextField magazyn_start = new JTextField();
        magazyn_start.setBounds(100, 100, 250, 20);
        panel.add(magazyn_start);

        final JTextField magazyn_end = new JTextField();
        magazyn_end.setBounds(100, 130, 250, 20);
        panel.add(magazyn_end);

        final JTextField dzien = new JTextField();
        dzien.setBounds(100, 160, 250, 20);
        panel.add(dzien);

        final JButton btn1 = new JButton("Zapisz");
        btn1.setBounds(100, 190, 100, 20);
        panel.add(btn1);

        final JButton btn2 = new JButton("Anuluj");
        btn2.setBounds(250, 190, 100, 20);
        panel.add(btn2);

        frame.setVisible(true);

        btn1.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                KurierRepository kurierRepository = new KurierRepository();
                KurierAggr kurierAggr = kurierRepository.znajdz(kurier_uuid.getText());
                //JOptionPane.showMessageDialog(null, kurierAggr.uuid());
                KurierService kurierService = new KurierService();
                if (kurierService.SprawdzTraseKuriera(kurierAggr.uuid(), Integer.parseInt(dzien.getText()), data_start.getText(), data_end.getText()) == 0) {
                    kurierAggr.KurierNowaTrasa(magazyn_start.getText(),magazyn_end.getText(), data_start.getText(), data_end.getText(), Integer.parseInt(dzien.getText()), kurier_uuid.getText(), UUID.randomUUID().toString());
                    //kurierAggr.KurierNowaTrasa(magazyn_start.getText(),magazyn_end.getText(), "dasda", "asds", 0, kurier_uuid.getText(), UUID.randomUUID().toString());

                    frame.dispose();
                }
                else{
                    JOptionPane.showMessageDialog(null, "Nie można dodać trasy");
                }


            }
        });
        btn2.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                frame.dispose();
            }
        });
    }

    public void OknoKlient(){
        final JFrame frame = new JFrame();
        frame.setLocation(100,100);
        frame.setTitle("dLogistic - klient");
        frame.setSize(400, 350);
        final JPanel panel=new JPanel();
        panel.setLayout(null);
        frame.add(panel);

        JLabel label1 = new JLabel();
        JLabel label2 = new JLabel();
        JLabel label3 = new JLabel();
        JLabel label4 = new JLabel();
        JLabel label5 = new JLabel();
        JLabel label6 = new JLabel();
        JLabel label7 = new JLabel();
        JLabel label8 = new JLabel();
        JLabel label9 = new JLabel();

        label1.setText("imie");
        label2.setText("nazwisko");
        label3.setText("telefon");
        label4.setText("email");
        label5.setText("ulica");
        label6.setText("numer domu");
        label7.setText("numer lokalu");
        label8.setText("kod");
        label9.setText("miasto");

        label1.setBounds(10, 10, 80, 20);
        label2.setBounds(10, 40, 80, 20);
        label3.setBounds(10, 70, 80, 20);
        label4.setBounds(10, 100, 80, 20);
        label5.setBounds(10, 130, 80, 20);
        label6.setBounds(10, 160, 80, 20);
        label7.setBounds(10, 190, 80, 20);
        label8.setBounds(10, 220, 80, 20);
        label9.setBounds(10, 250, 80, 20);

        panel.add(label1);
        panel.add(label2);
        panel.add(label3);
        panel.add(label4);
        panel.add(label5);
        panel.add(label6);
        panel.add(label7);
        panel.add(label8);
        panel.add(label9);

        final JTextField imie = new JTextField();
        final JTextField nazwisko = new JTextField();
        final JTextField telefon = new JTextField();
        final JTextField email = new JTextField();
        final JTextField ulica = new JTextField();
        final JTextField numer_domu = new JTextField();
        final JTextField numer_lokalu  = new JTextField();
        final JTextField kod_pocztowy = new JTextField();
        final JTextField miasto = new JTextField();

        imie.setBounds(100, 10, 250, 20);
        nazwisko.setBounds(100, 40, 250, 20);
        telefon.setBounds(100, 70, 250, 20);
        email.setBounds(100, 100, 250, 20);
        ulica.setBounds(100, 130, 250, 20);
        numer_domu.setBounds(100, 160, 250, 20);
        numer_lokalu.setBounds(100, 190, 250, 20);
        kod_pocztowy.setBounds(100, 220, 250, 20);
        miasto.setBounds(100, 250, 250, 20);

        panel.add(imie);
        panel.add(nazwisko);
        panel.add(telefon);
        panel.add(email);
        panel.add(ulica);
        panel.add(numer_domu);
        panel.add(numer_lokalu);
        panel.add(kod_pocztowy);
        panel.add(miasto);

        final JButton btn1 = new JButton("Zapisz");
        btn1.setBounds(100, 280, 100, 20);
        panel.add(btn1);

        final JButton btn2 = new JButton("Anuluj");
        btn2.setBounds(250, 280, 100, 20);
        //btn2.updateUI();
        panel.add(btn2);

        frame.setVisible(true);

        btn1.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                UUID uuid = UUID.randomUUID();
                KlientFactory klient = new KlientFactory();
                KlientAggr kli = klient.dodajKlienta(imie.getText(), nazwisko.getText(), telefon.getText(), email.getText());
                Adres adres = new Adres(ulica.getText(), numer_domu.getText(), numer_lokalu.getText(), miasto.getText(), kod_pocztowy.getText(), uuid.toString(), kli.uuid(), 0);

                frame.dispose();

                //return kli.uuid().toString();
            }
        });
        btn2.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                frame.dispose();
            }
        });
    }

    public void OknoMagazyn(){
        final JFrame frame = new JFrame();

        frame.setLocation(100, 100);
        frame.setTitle("dLogistic - magazyn");
        frame.setSize(400, 300);
        final JPanel panel=new JPanel();
        panel.setLayout(null);
        frame.add(panel);

        JLabel label1 = new JLabel();
        JLabel label2 = new JLabel();
        JLabel label3 = new JLabel();
        JLabel label4 = new JLabel();
        JLabel label5 = new JLabel();
        JLabel label6 = new JLabel();
        JLabel label7 = new JLabel();

        label1.setText("nazwa");
        label2.setText("sortowanie");
        label3.setText("ulica");
        label4.setText("numer domu");
        label5.setText("numer lokalu");
        label6.setText("kod");
        label7.setText("miasto");

        label1.setBounds(10, 10, 80, 20);
        label2.setBounds(10, 40, 80, 20);
        label3.setBounds(10, 70, 80, 20);
        label4.setBounds(10, 100, 80, 20);
        label5.setBounds(10, 130, 80, 20);
        label6.setBounds(10, 160, 80, 20);
        label7.setBounds(10, 190, 80, 20);

        panel.add(label1);
        panel.add(label2);
        panel.add(label3);
        panel.add(label4);
        panel.add(label5);
        panel.add(label6);
        panel.add(label7);

        final JTextField nazwa = new JTextField();
        nazwa.setBounds( 100, 10, 250, 20);
        panel.add(nazwa);

        final JTextField sortowanie = new JTextField();
        sortowanie.setBounds(100, 40, 250, 20);
        panel.add(sortowanie);

        final JTextField ulica = new JTextField();
        ulica.setBounds(100, 70, 250, 20);
        panel.add(ulica);

        final JTextField numer_domu = new JTextField();
        numer_domu.setBounds(100, 100, 250, 20);
        panel.add(numer_domu);

        final JTextField numer_lokalu  = new JTextField();
        numer_lokalu.setBounds(100, 130, 250, 20);
        panel.add(numer_lokalu);

        final JTextField kod_pocztowy = new JTextField();
        kod_pocztowy.setBounds(100, 160, 250, 20);
        panel.add(kod_pocztowy);

        final JTextField miasto = new JTextField();
        miasto.setBounds(100, 190, 250, 20);
        panel.add(miasto);

        final JButton btn1 = new JButton("Zapisz");
        btn1.setBounds(100, 220, 100, 20);
        panel.add(btn1);

        final JButton btn2 = new JButton("Anuluj");
        btn2.setBounds(250, 220, 100, 20);
        btn2.updateUI();
        panel.add(btn2);

        frame.setVisible(true);

        btn1.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                UUID uuid = UUID.randomUUID();
                MagazynFactory magazyn = new MagazynFactory();
                MagazynAggr mag = magazyn.dodajMagazyn(nazwa.getText(), Integer.parseInt(sortowanie.getText()));
                Adres adres = new Adres(ulica.getText(), numer_domu.getText(), numer_lokalu.getText(), miasto.getText(), kod_pocztowy.getText(), uuid.toString(), mag.uuid(), 1);

                frame.dispose();
            }
        });
        btn2.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                frame.dispose();
            }
        });
    }

    private class EventQueuePanel extends Component {
    }

    class z1 extends JPanel
    {
        public z1( )
        {

            setLayout(null);

            final JButton btn1 = new JButton("Nadanie paczki");
            btn1.setBounds(10,10,150,20);
            add(btn1);

            final JButton btn2 = new JButton("Zmiana statusu");
            btn2.setBounds(170,10,150,20);
            add(btn2);

            final JButton btn3 = new JButton("Status paczki");
            btn3.setBounds(10,40,150,20);
            add(btn3);

            btn1.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                OknoKlientLogowanie();
                //btn1.setText();
            }
        });
            btn2.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                OknoZmianStatus();
            }
        });

            btn3.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {
                    OknoSprawdzStatus();
               }
            });
        }
    }


    class z2 extends JPanel
    {
        public z2( )
        {
            setLayout(null);
            final JButton btn = new JButton("Dodaj klienta");
            btn.setBounds(10,10,150,20);
            add(btn);

            btn.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {
                    OknoKlient();
                }
            });
        }
    }

    class z3 extends JPanel
    {
        public z3( )
        {
            setLayout(null);
            final JButton btn = new JButton("Dodaj kuriera");
            btn.setBounds(10,10,150,20);
            add(btn);
            final JButton btn1 = new JButton("Dodaj kuriera - trasa");
            btn1.setBounds(170,10,150,20);
            add(btn1);

            final JButton btn2 = new JButton("Kurier - sprawdź");
            btn2.setBounds(10,40,150,20);
            add(btn2);

            btn.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    OknoKurier();
                }
            });

            btn1.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {
                    OknoKurierTrasa();
                }
            });
            btn2.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {
                    //do testów - uuid kuriera
                    String uuid_kuriera = "1c3e8101-09ab-4fac-b5e7-ef41ce2517fc";
                    KurierService kurierService = new KurierService();
                    if (kurierService.KurierWracaDoDomu(uuid_kuriera,0)){
                        JOptionPane.showMessageDialog(null, "Wraca do domu!");
                    }
                    else{
                        JOptionPane.showMessageDialog(null, "Trasa nie jest pełna :(");
                    }
                }
            });
        }
    }


    class z4 extends JPanel
    {
        public z4( )
        {
            setLayout(null);
            final JButton btn = new JButton("Dodaj magazyn");
            btn.setBounds(10,10,150,20);
            add(btn);
            btn.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {
                    OknoMagazyn();
                }
            });

            final JButton btn2 = new JButton("geo");
            btn2.setBounds(10,40,150,20);

            //do testów
            //add(btn2);
            btn2.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {
                    GeolokalizacjaService geo = new GeolokalizacjaService();
                    ArrayList geoLok = geo.wyznaczGeolokalizacje("Długa", "51c","39","Toruń","87-100");
                    btn.setText(geoLok.get(0).toString());
                    btn2.setText(geoLok.get(1).toString());
                }
            });

            final JButton btn3= new JButton("find");
            btn3.setBounds(10,70,150,20);
            //do testów
            //add(btn3);

            btn3.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {
                    KlientRepository klientRepository = new KlientRepository();
                    KlientAggr klientAggr = klientRepository.znajdz("3eb6494f-226a-4938-a675-59eb6fa1ecb0");

                    btn.setText(klientRepository.najblizszyMagazyn(klientAggr).nazwa());

                }
            });

        }
    }
}
